package com.phkj.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

public class Send {

  private final static String QUEUE_NAME = "work-example";

      public static void main(String[] argv)  throws Exception {

          ConnectionFactory factory = new ConnectionFactory();
          factory.setHost("localhost");
          Connection connection = factory.newConnection();
          Channel channel = connection.createChannel();

          channel.queueDeclare(QUEUE_NAME, true, false, false, null);

          //消息内容
          for(int i=0;i<5;i++){
          String message = "消息001需要处理"+i;
              channel.basicPublish( "", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
              System.out.println(" 后端系统发送 '" + message + "'");
              Thread.sleep(i * 10);
          }
          channel.close();
          connection.close();
      }
}    